package net.jxtz.jxtzos.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author lmh
 */
@Configuration
@EnableTransactionManagement
@MapperScan("net.jxtz.jxtzos.mapper")
public class MybatisPlusConfig implements MetaObjectHandler {

    @Bean
    MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return mybatisPlusInterceptor;
    }


    @Override
    public void insertFill(MetaObject metaObject) {
        long l = System.currentTimeMillis();
        Integer integer = Integer.valueOf((int) (l / 1000));
        this.strictInsertFill(metaObject, "createTime", Integer.class, integer);
        this.strictInsertFill(metaObject, "updateTime", Integer.class, integer);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        long l = System.currentTimeMillis();
        Integer integer = Integer.valueOf((int) (l / 1000));
        this.strictUpdateFill(metaObject, "updateTime", Integer.class, integer);
    }
}
